package com.evan.webadmin.biz.helper;

import com.evan.common.dict.model.GlobalDictItem;
import com.evan.common.dict.service.GlobalDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Component
public class DictHelper {

    @Autowired
    GlobalDictService globalDictService;

    public Map<String, String> getDictMap(String dictCode) {
        List<GlobalDictItem> subjectList = globalDictService.getGlobalDictItemListFromCache(dictCode, null);
        return subjectList.stream().collect(Collectors.toMap(GlobalDictItem::getItemId, GlobalDictItem::getItemName));
    }

    public Map<String, String> getDictNameMap(String dictCode) {
        List<GlobalDictItem> subjectList = globalDictService.getGlobalDictItemListFromCache(dictCode, null);
        return subjectList.stream().collect(Collectors.toMap(GlobalDictItem::getItemName, GlobalDictItem::getItemId));
    }
}
